package com.tedu.weibo.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

@Configuration
@MapperScan("com.tedu.weibo.mapper")
@EnableSwagger2WebMvc
public class Knife4jConfig {
    //配置Swagger2的Docket的Bean实例
    @Bean
    public Docket createRestApi(){
        /*apiInfo():配置API的一些基本信息,比如:文档标题Title,文档描述
        * description,文档版本号version*/
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                /*select():生成API文档的选择器,用于指定要生成哪些API文档*/
                .select()
                //apis():指定要生成哪个包下的API文档
                .apis(RequestHandlerSelectors.basePackage("com.tedu.weibo.controller"))
                //paths():指定要生成路径下哪个的controller类的API文档,这里使用
        // PathSelectors.any()表示生成路径下所有controller类的API文档
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                //文档标题
                .title("达达微博项目")
                //文档描述信息
                .description("达达微博项目在线文档")
                //文档版本号
                .version("1.0")
                //生成作者信息
                .contact(new Contact("飘逸的风","www.tedu.com","feng@tedu.cn"))
                .build();
    }
}
